var app = getApp();
Page({
  data: {
    //收货地址
    shippingAddressList: []
  },
  onLoad: function(options) {
    //找到系统状态位置
    this.setData({
      statusBarHeight: app.globalData.systemInfo.statusBarHeight + 15
    })
    this.getShippingAddress();
  },

  //获取收货地址
  getShippingAddress: function() {
    var that = this;
    wx.request({
      url: app.globalData.requestUrl + 'getShippingAddress',
      data: {
        userId: app.globalData.user.id
      },
      method: 'GET',
      success: function(r) {
        if (r.data.code == 200) {
          that.setData({
            shippingAddressList: r.data.data
          })
        }
        else {
          wx.showToast({
            title: '获取收货地址失败',
            duration: 2000,
            icon: 'none'
          })
        }
      },
      fail: function() {
        wx.showToast({
          title: '网络断开连接,获取收货地址失败',
          duration: 2000,
          icon: 'none'
        })
      }
    })
  },
  // 返回下一个页面
  rollback: function() {
    wx.navigateBack({
      delta: 1
    })
  },
  //添加
  addAddress: function() {
    wx.navigateTo({
      url: '/pages/addAddress/addAddress',
    })
  },
  //修改
  updateShippingAddress:function(e){
    var index  = e.currentTarget.dataset.index;
    var address = this.data.shippingAddressList[index];
    wx.navigateTo({
      url: '/pages/updateShippingAddress/updateShippingAddress?address='+JSON.stringify(address),
    })
  }
})